/*
@author   : wang lingcong
@date     : 2022/10/31
@desc     : 入口文件
*/
import React from 'react'
import ReactDOM from 'react-dom/client'
import { App } from './app'
import { FastClick } from 'fastclick'

FastClick.attach(document.body)
FastClick.prototype.focus = function (targetElement: {
  setSelectionRange: (arg0: any, arg1: any) => void
  type: string | string[]
  value: string | any[]
  focus: () => void
}) {
  let length
  if (
    targetElement.setSelectionRange &&
    targetElement.type.indexOf('date') !== 0 &&
    targetElement.type !== 'time' &&
    targetElement.type !== 'month'
  ) {
    length = targetElement.value.length
    targetElement.focus()
    targetElement.setSelectionRange(length, length)
  } else {
    targetElement.focus()
  }
}

const mountDomInnerApp = () => {
  const rootDom = document.getElementById('root') as HTMLElement
  const rootDomInnerHTML = rootDom.innerHTML
  if (!rootDomInnerHTML) {
    const rootContext = ReactDOM.createRoot(rootDom)
    rootContext.render(<App />)
  } else {
    window.location.reload()
  }
}

mountDomInnerApp()
